<?php

defined('SYSPATH') or die('Access error!');

class Controller_User_Company extends Controller_User_Main
{

    protected $user;

    public function before()
    {
        parent::before();
        $this->user = Model::factory('user');
    }

    //公司信息
    public function action_profile()
    {
        //当前位置
        $this->set_define_position(__('company info'));

        //获取当前用户的公司资料
        $company_detail = $this->user->get_company_info_by_id($this->user_detail['id']);

        //获取单位性质
        $company_attr_list = $this->user->get_related_category(USER_COMPANY_ATTR_ID);
        //获取工作性质
        $job_attr_list = $this->user->get_related_category(USER_JOB_ATTR_ID);
        //获取用户的职务列表
        $job_list = $this->user->get_related_category(USER_JOB_ID);
        //获取用户的专业
        $work_list = $this->user->get_related_category(USER_WORD_ID);
        $this->template->assign('company_attr_list', $company_attr_list);
        $this->template->assign('job_attr_list', $job_attr_list);
        $this->template->assign('work_list', $work_list);
        $this->template->assign('job_list', $job_list);
        $this->template->assign('data', $company_detail);
        $this->template->view('user_company_profile');
    }

    //保存公司信息
    public function action_save_profile()
    {
        if ($_POST)
        {
            $data = array();
            $data['company_name'] = Arr::get($_POST, 'company_name', '');
            $data['company_attr'] = Arr::get($_POST, 'company_attr', '');
            $data['company_work_attr'] = Arr::get($_POST, 'company_work_attr', '');
            if (isset($_POST['company_works']) && count($_POST['company_works']) > 0)
            {
                $data['company_works'] = implode(',', $_POST['company_works']);
            }
            $data['company_job'] = Arr::get($_POST, 'company_job', '');
            $data['company_address'] = Arr::get($_POST, 'company_address', '');
            $data['company_code'] = Arr::get($_POST, 'company_code', '');
            $data['company_phone'] = Arr::get($_POST, 'company_phone', '');
            $data['company_description'] = HTML::cut_bad_code(Arr::get($_POST, 'company_description', ''), 3);
            if ($this->user->update($data, array('id' => $this->user_detail['id'])))
            {
                Message::success( __('update company success'));
                $this->request->redirect('usercompany/profile');
            }

            Message::success( __('update company error'));
            $this->request->redirect('usercompany/profile');
        }
    }



}